//utf-8
//点击新增按钮 事件跳转至 新增页面
function toAddData(){
	var obj={"text":'新建费用参数',"url":contextRootPath+'/tCMmCostParam/prepareExecute/toAdd'};
	parent.showObj(obj);
}
//新增页面的保存操作
function doAddFrom(){
	//序列化 新增页面的form表单数据
	var params=$("#addNewsFormData").serialize();
	var params=$("#copyNewsFormData").serialize();
	var costCode = $('#dtocostCode').val();
	var costName = $('#dtocostName').val();
	var countType = $('#dtocountType').val();
	var serviceFeeRatio = $('#dtoserviceFeeRatio').val();
	var serviceFeeBase = $('#dtoserviceFeeBase').val();
	var packageRatio = $('#dtopackageRatio').val();
	var guaranteeFeeBase = $('#dtoguaranteeFeeBase').val();
	var guaranteeFeeRatio = $('#dtoguaranteeFeeRatio').val();
	var marginBase = $('#dtomarginBase').val();
	var marginRatio = $('#dtomarginRatio').val();
	var beginDate = $('#dtobeginDate').val();
	var endDate = $('#dtoendDate').val();
	var url=contextRootPath+'/tCMmCostParam/insertTCMmCostParam';
	

	var reg = new RegExp("^[0]{1}.\\d{0,4}$");
	if(costCode==null || costCode==""){
		art.dialog({title: '提示', content: '请输入费用编号！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(costName==null || costName==""){
		art.dialog({title: '提示', content: '输入费用名称！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(beginDate==null || beginDate==""){
		art.dialog({title: '提示', content: '请输入起始时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(endDate==null || endDate==""){
		art.dialog({title: '提示', content: '请输入失效时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(serviceFeeBase==null || serviceFeeBase==""){
		art.dialog({title: '提示', content: '请选择服务费率基数！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(serviceFeeRatio==null || serviceFeeRatio==""){
		art.dialog({title: '提示', content: '请输入服务费率！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(beginDate>endDate){
		art.dialog({title: '提示', content: '结束时间不能大于起始时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(countType==null || countType==""){
		art.dialog({title: '提示', content: '请选择计算方式！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}else if("02"==countType){
		if(packageRatio==null || packageRatio==""){
			art.dialog({title: '提示', content: '请输入打包价！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	if(!reg.test(serviceFeeRatio)){
		art.dialog({title: '提示', content: '服务费费率必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	
	if(guaranteeFeeBase!=null&&guaranteeFeeBase!=""){
		if(guaranteeFeeRatio==null || guaranteeFeeRatio==""){
			art.dialog({title: '提示', content: '请输入担保费比例！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	
	if(guaranteeFeeRatio!=null&&guaranteeFeeRatio!=""){
		if(!reg.test(guaranteeFeeRatio)){
			art.dialog({title: '提示', content: '担保费比例必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	
	if(marginBase!=null&&marginBase!=""){
		if(marginRatio==null || marginRatio==""){
			art.dialog({title: '提示', content: '请输入保证金比例！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	if(marginRatio!=null&&marginRatio!=""){
		if(!reg.test(marginRatio)){
			art.dialog({title: '提示', content: '保证金比例必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	//通过ajax保存
	$.ajax({
		url: url,
		type: 'post',
		dataType: 'json',
		data:{"costCode":costCode,
			"costName":costName,
			"countType":countType,
			"serviceFeeRatio":serviceFeeRatio,
			"serviceFeeBase":serviceFeeBase,
			"packageRatio":packageRatio,
			"guaranteeFeeBase":guaranteeFeeBase,
			"guaranteeFeeRatio":guaranteeFeeRatio,
			"marginBase":marginBase,
			"marginRatio":marginRatio,
			"beginDate":beginDate,
			"endDate":endDate},
		success: function(msg) {
			var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
        		
        		var winObj = parent.tabs.getTabWinByTitle("费用管理");
        		parent.tabs.close();
				if(winObj)
					winObj.location.reload();
        	}
        	else{
        		art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
        	}
		}
	});
}
//修改 事件
function toUpdateData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		art.dialog({title: '提示', content: '请选择一条数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		art.dialog({title: '提示', content: '请选择一条数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}

	var obj={"text":'修改费用参数',"url":contextRootPath+'/tCMmCostParam/prepareExecute/toUpdate?id='+v_ids};
	parent.showObj(obj);
}
//修改页面 的 保存操作
function doUpdateFrom(){
	//序列化 新增页面的form表单数据
	var params=$("#copyNewsFormData").serialize();
	var id = $('#dtoid').val();
	var costCode = $('#dtocostCode').val();
	var costName = $('#dtocostName').val();
	var countType = $('#dtocountType').val();
	var serviceFeeRatio = $('#dtoserviceFeeRatio').val();
	var serviceFeeBase = $('#dtoserviceFeeBase').val();
	var packageRatio = $('#dtopackageRatio').val();
	var guaranteeFeeBase = $('#dtoguaranteeFeeBase').val();
	var guaranteeFeeRatio = $('#dtoguaranteeFeeRatio').val();
	var marginBase = $('#dtomarginBase').val();
	var marginRatio = $('#dtomarginRatio').val();
	var beginDate = $('#dtobeginDate').val();
	var endDate = $('#dtoendDate').val();
	var url=contextRootPath+'/tCMmCostParam/updateTCMmCostParam';

	var reg = new RegExp("^[0]{1}.\\d{0,4}$");
	if(costCode==null || costCode==""){
		art.dialog({title: '提示', content: '请输入费用编号！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(costName==null || costName==""){
		art.dialog({title: '提示', content: '输入费用名称！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(beginDate==null || beginDate==""){
		art.dialog({title: '提示', content: '请输入起始时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(endDate==null || endDate==""){
		art.dialog({title: '提示', content: '请输入失效时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(serviceFeeBase==null || serviceFeeBase==""){
		art.dialog({title: '提示', content: '请选择服务费率基数！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(serviceFeeRatio==null || serviceFeeRatio==""){
		art.dialog({title: '提示', content: '请输入服务费率！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(beginDate>endDate){
		art.dialog({title: '提示', content: '结束时间不能大于起始时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(countType==null || countType==""){
		art.dialog({title: '提示', content: '请选择计算方式！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}else if("02"==countType){
		if(packageRatio==null || packageRatio==""){
			art.dialog({title: '提示', content: '请输入打包价！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	if(!reg.test(serviceFeeRatio)){
		art.dialog({title: '提示', content: '服务费费率必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	
	if(guaranteeFeeBase!=null&&guaranteeFeeBase!=""){
		if(guaranteeFeeRatio==null || guaranteeFeeRatio==""){
			art.dialog({title: '提示', content: '请输入担保费比例！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	
	if(guaranteeFeeRatio!=null&&guaranteeFeeRatio!=""){
		if(!reg.test(guaranteeFeeRatio)){
			art.dialog({title: '提示', content: '担保费比例必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	
	if(marginBase!=null&&marginBase!=""){
		if(marginRatio==null || marginRatio==""){
			art.dialog({title: '提示', content: '请输入保证金比例！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	if(marginRatio!=null&&marginRatio!=""){
		if(!reg.test(marginRatio)){
			art.dialog({title: '提示', content: '保证金比例必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	//通过ajax保存
	$.ajax({
		url: url,
		type: 'post',
		dataType: 'json',
		data:{
			"id":id,
			"costCode":costCode,
			"costName":costName,
			"countType":countType,
			"serviceFeeRatio":serviceFeeRatio,
			"serviceFeeBase":serviceFeeBase,
			"packageRatio":packageRatio,
			"guaranteeFeeBase":guaranteeFeeBase,
			"guaranteeFeeRatio":guaranteeFeeRatio,
			"marginBase":marginBase,
			"marginRatio":marginRatio,
			"beginDate":beginDate,
			"endDate":endDate},
		success: function(msg) {
			art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
			var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		var winObj = parent.tabs.getTabWinByTitle("费用管理");
        		parent.tabs.close();
				if(winObj)
					winObj.location.reload();
        	}
		}
	});
}

//复制 事件
function toCopyData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		art.dialog({title: '提示', content: '请选择一条数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		art.dialog({title: '提示', content: '请选择一条数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}

	var obj={"text":'复制费用参数',"url":contextRootPath+'/tCMmCostParam/prepareExecute/toCopy?id='+v_ids};
	parent.showObj(obj);
}
//复制页面 的 保存操作
function doCopyFrom(){
	//序列化 新增页面的form表单数据
	var params=$("#copyNewsFormData").serialize();
	var costCode = $('#dtocostCode').val();
	var costName = $('#dtocostName').val();
	var countType = $('#dtocountType').val();
	var serviceFeeRatio = $('#dtoserviceFeeRatio').val();
	var serviceFeeBase = $('#dtoserviceFeeBase').val();
	var packageRatio = $('#dtopackageRatio').val();
	var guaranteeFeeBase = $('#dtoguaranteeFeeBase').val();
	var guaranteeFeeRatio = $('#dtoguaranteeFeeRatio').val();
	var marginBase = $('#dtomarginBase').val();
	var marginRatio = $('#dtomarginRatio').val();
	var beginDate = $('#dtobeginDate').val();
	var endDate = $('#dtoendDate').val();

	var url=contextRootPath+'/tCMmCostParam/insertTCMmCostParam';

	var reg = new RegExp("^[0]{1}.\\d{0,4}$");
	if(costCode==null || costCode==""){
		art.dialog({title: '提示', content: '请输入费用编号！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(costName==null || costName==""){
		art.dialog({title: '提示', content: '输入费用名称！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(beginDate==null || beginDate==""){
		art.dialog({title: '提示', content: '请输入起始时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(endDate==null || endDate==""){
		art.dialog({title: '提示', content: '请输入失效时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(serviceFeeBase==null || serviceFeeBase==""){
		art.dialog({title: '提示', content: '请选择服务费率基数！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(serviceFeeRatio==null || serviceFeeRatio==""){
		art.dialog({title: '提示', content: '请输入服务费率！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(beginDate>endDate){
		art.dialog({title: '提示', content: '结束时间不能大于起始时间！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	if(countType==null || countType==""){
		art.dialog({title: '提示', content: '请选择计算方式！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}else if("02"==countType){
		if(packageRatio==null || packageRatio==""){
			art.dialog({title: '提示', content: '请输入打包价！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	if(!reg.test(serviceFeeRatio)){
		art.dialog({title: '提示', content: '服务费费率必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	
	if(guaranteeFeeBase!=null&&guaranteeFeeBase!=""){
		if(guaranteeFeeRatio==null || guaranteeFeeRatio==""){
			art.dialog({title: '提示', content: '请输入担保费比例！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	
	if(guaranteeFeeRatio!=null&&guaranteeFeeRatio!=""){
		if(!reg.test(guaranteeFeeRatio)){
			art.dialog({title: '提示', content: '担保费比例必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	
	if(marginBase!=null&&marginBase!=""){
		if(marginRatio==null || marginRatio==""){
			art.dialog({title: '提示', content: '请输入保证金比例！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	if(marginRatio!=null&&marginRatio!=""){
		if(!reg.test(marginRatio)){
			art.dialog({title: '提示', content: '保证金比例必须小于1，且小数点最多4位！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
			return;
		}
	}
	//通过ajax保存
	$.ajax({
		url: url,
		type: 'post',
		dataType: 'json',
		data:{"costCode":costCode,
			"costName":costName,
			"countType":countType,
			"serviceFeeRatio":serviceFeeRatio,
			"serviceFeeBase":serviceFeeBase,
			"packageRatio":packageRatio,
			"guaranteeFeeBase":guaranteeFeeBase,
			"guaranteeFeeRatio":guaranteeFeeRatio,
			"marginBase":marginBase,
			"marginRatio":marginRatio,
			"beginDate":beginDate,
			"endDate":endDate},
		success: function(msg) {
			var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		try{
        			art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
        			var winObj = parent.tabs.getTabWinByTitle("费用管理");
            		parent.tabs.close();
    				if(winObj)
    					winObj.location.reload();
    				
    			}catch(e){
    				
    			}finally{
    				//parent.tabs.close();
    			}
        	}
        	else{
        		art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
        	}
		}
	});
}
//删除 事件
function deleteData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		//alert("请选择待删除的数据！");
		art.dialog({title: '提示', content: '请选择待删除的数据！', ok: function () {return true; }, icon: 'warning', lock:true, background:'#600', opacity: 0.10});
		return;
	}
	art.dialog({title: '询问', content: '您确认要删除选择的数据吗？', ok: function () {
		  $.ajax({
				url: contextRootPath+"/tCMmCostParam/deleteTCMmCostParam?ids="+v_ids,
				type: 'post',
				dataType: 'json',
				success: function(msg) {
						art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
						var v_status = msg.status;
		            	//删除成功后
		            	if(v_status.indexOf('ok') >-1){
		            		iframe.iframeObj["table"].removeSelectedRow();
		            	}
				}
			});
	  }, cancel: true, icon: 'question', lock:true, background:'#600', opacity: 0.10});
}
//查看明细
function viewData(vId){

	var obj={"text":'查看费用参数',"url":contextRootPath+'/tCMmCostParam/prepareExecute/toView?id='+vId};
	parent.showObj(obj);
}